1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class GameControllers : MonoBehaviour {
6
7     
public static GameControllers instance;
8
9     
private const string HIGH_SCORE = "High Score";
10     
private const string SELECTED_BIRD = "Selected Bird";
11     
private const string GREEN_BIRD = "Green Bird";
12     
private const string RED_BIRD = "Red Bird";
13
14     
void Awake(){
15         MakeSingleton ();
16         isGameStartedFirstTime ();
17
18     }
19         
20     
// Use this for initialization
21     
void Start () {
22         
23     }
24     
25     
// Update is called once per frame
26     
void MakeSingleton () {
27         
if (instance != null) {
28             Destroy (gameObject);
29         }
else {
30             instance =
this;
31             DontDestroyOnLoad (gameObject);
32         }
33     }
34         
35     
void isGameStartedFirstTime() {
36         
if (!PlayerPrefs.HasKey ("isGameStartedFirstTime")) {
37             PlayerPrefs.SetInt (HIGH_SCORE,
0);
38             PlayerPrefs.SetInt (SELECTED_BIRD,
0);
39             PlayerPrefs.SetInt (GREEN_BIRD,
1);
40             PlayerPrefs.SetInt (RED_BIRD,
1);
41             PlayerPrefs.SetInt (
"isGameStartedFirstTime", 0);
42         }
43     }
44
45     
public void SetHighScore(int score){
46         PlayerPrefs.SetInt (HIGH_SCORE, score);
47     }
48
49     
public int GetHighScore() {
50         
return PlayerPrefs.GetInt (HIGH_SCORE);
51     }
52
53     
public void SetSelectedBird(int selectedBird){
54         PlayerPrefs.SetInt (SELECTED_BIRD, selectedBird);
55     }
56
57     
public int GetSelectedBird() {
58         
return PlayerPrefs.GetInt (SELECTED_BIRD);
59     }
60
61     
public void UnlockGreenBird() {
62         PlayerPrefs.SetInt (GREEN_BIRD,
1);
63     }
64
65     
public int IsGreenBirdUnlocked() {
66         
return PlayerPrefs.GetInt (GREEN_BIRD);
67     }
68
69     
public void UnlockRedBird() {
70         PlayerPrefs.SetInt (RED_BIRD,
1);
71     }
72
73     
public int IsRedBirdUnlocked() {
74         
return PlayerPrefs.GetInt (RED_BIRD);
75     }
76
77 }


Gõ tìm kiếm nhanh...